package com.soft.controller;

import com.soft.domain.Account;
import com.soft.domain.TransferInfo;
import com.soft.service.IAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private IAccountService accountService;

    //查询所有的账户
//    @RequestMapping("/findAll")
//    public String findAll(){
//        System.out.println("表现层--->查询所有的帐户");
//
//        List<Account> accounts = accountService.findAll();
//        System.out.println(accounts);
//
//        return "success";
//    }

    //查询所有的账户
    // ModelAndView(把数据携带到jsp上去)   Model:数据   View:jsp
    @RequestMapping("/findAll")
    public ModelAndView findAll(){
        System.out.println("表现层--->查询所有的帐户");

        List<Account> accounts = accountService.findAll();
        System.out.println(accounts);

        //创建modelAndView
        ModelAndView modelAndView = new ModelAndView();
        //设置数据与视图
        modelAndView.addObject("accounts",accounts);
        modelAndView.setViewName("success");

        return modelAndView;
    }

    @RequestMapping("/transfer")
    public String transfer(TransferInfo transferInfo){

        System.out.println("控制层:"+transferInfo);
        //转账
        accountService.transfer(transferInfo);

        return "success";
    }

    @RequestMapping("/info")
    public String info(String username,String password){

        System.out.println(username);
        System.out.println(password);
        return "success";
    }

}
